package com.jysz.certificate.persistence.dao.cs.tn;

import java.util.List;

import org.hibernate.SQLQuery;
import org.hibernate.type.LongType;
import org.springframework.stereotype.Repository;

import com.jysz.certificate.persistence.dao.AbstractBaseDao;
import com.jysz.certificate.persistence.model.cs.TheNetwork;

@Repository
public class TheNetworkDao extends AbstractBaseDao<TheNetwork,Long>{
	
	public Long[] cerIds(Long[] ids){
		StringBuilder sb = new StringBuilder("SELECT fs_._certification_id AS id FROM cs_the_network_ cs_ LEFT JOIN sys_financial_ f_ ON(cs_._financial_id= f_.id)  LEFT JOIN cs_the_network_list_ fs_ ON(cs_.id= fs_._theNetwork_id) WHERE DATE_FORMAT(cs_._applicationDate, 'yyyy-MM-dd') <= DATE_ADD(CURDATE(), INTERVAL f_._fatalism*-1 DAY)");
		SQLQuery q= getSession().createSQLQuery(sb.toString());
		q.addScalar("id", LongType.INSTANCE);
		List<Object> list = q.list();
		Long[] idsLongs = new Long[list.size()];
		for(int i=0;i<list.size();i++){
			Object obj = list.get(i);
			idsLongs[i] = (Long) obj;
		}
		return idsLongs;
	}
}
